const app = getApp()
Page({
  data: {
    loading: true,
    active:0,
    types:0,
    page:0,
    engineer:0,
    order: []
  },
  //监听页面加载
  onShow: function () {
    this.getApi(0);
    this.setData({
      active: 0,
    })
    console.log(this.data.active)
  },
  //上拉加载
  onReachBottom: function () {
    this.setData({
      loading: true,
    });
    this.getList(this.data.types);
  },
  //获取API判断是否工程师
  getApi:function(){
    var parms = {
      signkey:'engineer'
    }
    app.api().Get('api/v1/bestbao/engineer/isEngineer', parms, (result) => {
      this.setData({
        engineer: result.data,
        loading: true,
        page:0,
        order: [],
      })
      this.getList(this.data.types);
    })
  },
  //获取API
  getList: function (types) {
    if (this.data.loading) {
      var parms = {
        page: this.data.page + 1,
        types: types
      }
      var url = this.data.engineer ? 'engineer' :'order';
      app.api().Get('api/v1/bestbao/' + url+'/index',parms,(result) => {
        if (result.code == 200) {
          var order = this.data.order;
          for (let i in result.data) {
            order.push(result.data[i]);
          }
          this.setData({
            order: order,
            page: parms.page,
          });
        }else{
          if (parms.page == 1){
            this.setData({
              order: []
            });
          }
        }
      })
      this.setData({
        loading: false,
      });
    }
  },
  //点击表情
  onChange(event) {
    let types = event.detail.name;
    this.setData({
      loading: true,
      types: types,
      page: 0,
      order: [],
    })
    this.getList(types);
  }
})